/*
 * @features: 扩展cc方法
 * @description: 说明
 * @Date: 2021-09-25 16:50:04
 * @Author: judu233(769471424@qq.com)
 * @LastEditTime: 2021-10-11 23:13:32
 * @LastEditors: judu233
 */
import { director } from "cc";
import { EDITOR } from "cc/env";
import c3d from "../cc";

declare module "cc" {
    /**设置游戏速率 */
    export function kSetSpeed(speed: number): void;
    /**获取游戏速率 */
    export function kGetSpeed(): number;
}


export default class ExtendsLoad {
    /**
     * 拷贝指定对象上的方法到指定目标
     * @param target 目标 
     * @param value 对象
     * @param isCopyAll 是否拷贝所有的属性（默认只拷贝方法，不拷贝数据）
     */
    static load(target, value, isCopyAll = false) {
        // c3d.log(`in load: ${value}`)
        if (EDITOR) return;
        let valueArr = Reflect.ownKeys(value) as string[];
        for (let i of valueArr) {
            let v = value[i];
            let nameList = ['prototype', 'length '];
            if ((typeof v == 'function' || isCopyAll) && !nameList.includes(i)) {
                target[i] = v;
                // console.log(`${i}:${v}`);
            }
        }
    }
}


/** 全局游戏动画数度设置 */
class CCExtends {
    static kSetSpeed(speed: number) {
        director._kSpeed = speed;
    }

    static kGetSpeed() {
        return director._kSpeed;
    }
}

ExtendsLoad.load(window['cc'], CCExtends);
